package com.example.demo.tcp;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;

/**
 * description: <h1>通道初始化</h1>
 *
 * @author bo
 * @version 1.0
 * @date 2024/2/27 16:13
 */
public class TcpNettyChannelInitializer<SocketChannel> extends ChannelInitializer<Channel> {

    @Override
    protected void initChannel(Channel ch) throws Exception {

        ByteBuf delemiter = Unpooled.buffer();
        delemiter.writeBytes("$".getBytes());
        // 这里就是解决数据过长问题，而且数据是以$结尾的
//        ch.pipeline().addLast(new DelimiterBasedFrameDecoder(907200, true, true, delemiter));

        // 自定义ChannelInboundHandlerAdapter
        ch.pipeline().addLast(new TcpNettyChannelInboundHandlerAdapter());

    }

}
